part of 'page.dart';

class _AllWordPageTranslation {
  static final delegate = _AllWordPageTranslationDelegate();

  static _AllWordPageTranslation of(BuildContext context) {
    return Localizations.of(context, _AllWordPageTranslation);
  }

  late String _languageCode;

  Future<void> load(Locale locale) async {
    _languageCode = locale.languageCode;
  }

  String _resolve(Map<String, String> translations) {
    return translations[_languageCode]!;
  }

  String get numberTableColumnHeader {
    return _resolve(const {
      'en': '№',
    });
  }

  String get titleTableColumnHeader {
    return _resolve(const {
      'en': 'Title',
    });
  }

  String get partOfSpeechTableColumnHeader {
    return _resolve(const {
      'en': 'Part of speech',
    });
  }

  String get cefrLevelTableColumnHeader {
    return _resolve(const {
      'en': 'CEFR level',
    });
  }

  String get rankTableColumnHeader {
    return _resolve(const {
      'en': 'Rank',
    });
  }

  String get translationTableColumnHeader {
    return _resolve(const {
      'en': 'Translation',
    });
  }

  String buildCefrLevelLabel({
    required CefrLevel cefrLevel,
  }) {
    return switch (cefrLevel) {
      CefrLevel.a1 => 'A1',
      CefrLevel.a2 => 'A2',
      CefrLevel.b1 => 'B1',
      CefrLevel.b2 => 'B2',
      CefrLevel.c1 => 'C1',
      CefrLevel.c2 => 'C2',
    };
  }

  String buildWordPartOfSpeechLabel({
    required Word word,
  }) {
    return switch (word) {
      UnspecifiedWord() => _resolve(const {
          'en': 'unspecified',
        }),
      Adjective() => _resolve(const {
          'en': 'adjective',
        }),
      Adverb() => _resolve(const {
          'en': 'adverb',
        }),
      Conjunction() => _resolve(const {
          'en': 'conjunction',
        }),
      Noun() => _resolve(const {
          'en': 'noun',
        }),
      Numeral() => _resolve(const {
          'en': 'numeral',
        }),
      Preposition() => _resolve(const {
          'en': 'preposition',
        }),
      Pronoun() => _resolve(const {
          'en': 'pronoun',
        }),
      Verb() => _resolve(const {
          'en': 'verb',
        }),
    };
  }
}

class _AllWordPageTranslationDelegate extends LocalizationsDelegate<_AllWordPageTranslation> {
  @override
  bool isSupported(Locale locale) => const ['en'].contains(locale.languageCode);

  @override
  bool shouldReload(LocalizationsDelegate<_AllWordPageTranslation> old) => false;

  @override
  Future<_AllWordPageTranslation> load(Locale locale) async {
    final translation = _AllWordPageTranslation();
    await translation.load(locale);
    return translation;
  }
}
